// 创建router实例 导出

import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'
import Home from '@/views/home/index.vue'

export default createRouter({
  // 模式 hash history
  history: createWebHashHistory(),
  // 希望路由切换时 能够让滚动条回到顶部 => 人资
  // 233 344
  // vue-router 4的语法 {top: 0} => vue3
  // vue-router 3的语法 {y: 0} => vue2
  // 配置滚动行为
  scrollBehavior: () => {
    return {
      top: 0,
    }
  },
  routes: [
    // layout架子
    {
      path: '/',
      component: Layout,
      children: [
        { path: '', component: Home },
        // 一级分类
        {
          path: 'category/:id',
          component: () => import('@/views/category/index.vue'),
        },
        // 二级分类
        {
          path: 'category/sub/:id',
          component: () => import('@/views/category/sub.vue'),
        },
        {
          path: '/goods/:id',
          component: () => import('@/views/goods/index.vue'),
        },
      ],
    },
    // login
    {
      path: '/login',
      component: () => import('@/views/login/index.vue'),
    },
    // 测试专用路由
    {
      path: '/playground',
      component: () => import('@/views/playground/index.vue'),
    },
  ],
})
